package com.tanhua.server.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.server.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {
    @Autowired
    private TanhuaService tanhuaService;
    @GetMapping("/todayBest")
    public ResponseEntity todayBest(){
        TodayBest todayBest = tanhuaService.todayBest();
        return ResponseEntity.ok().body(todayBest);
    }
    //分页查询推荐用户数据，前端分页不需要总数，page，size等，只需要items，即数据列表
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize){
        PageResult resultPage = tanhuaService.recommendation(page,pageSize);
        return ResponseEntity.ok().body(resultPage);
    }
    //查询详细信息
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long id){
       TodayBest todayBest = tanhuaService.personalInfo(id);
        return ResponseEntity.ok(todayBest);
    }
    //加好友查陌生人问题
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId){
        String txt = tanhuaService.strangerQuestions(userId);
        return ResponseEntity.ok(txt);
    }
    //回复陌生人问题
    @PostMapping("/strangerQuestions")
    public ResponseEntity replyQuestion(@RequestBody Map map){
        String string = map.get("userId").toString();
        Long userId = Long.valueOf(string);
        String reply = map.get("reply").toString();
        tanhuaService.replyQuestion(userId,reply);
        return ResponseEntity.ok(null);
    }

    //搜附近
    //get  /search
    // query  gender distance
    //返回值  NearUservo

    @GetMapping("/search")
    public ResponseEntity search(String gender,String distance){
     List<NearUserVo> list = tanhuaService.search(gender,distance);
        return ResponseEntity.ok(list);
    }
}
